package com.a1;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

// 库存管理类
class InventoryManagement {
    private Map<String, Integer> inventory;

    public InventoryManagement() {
        this.inventory = new HashMap<>();
    }

    public void addProduct(String productName, int quantity) {
        if (inventory.containsKey(productName)) {
            int currentQuantity = inventory.get(productName);
            inventory.put(productName, currentQuantity + quantity);
        } else {
            inventory.put(productName, quantity);
        }
        JOptionPane.showMessageDialog(null,
                String.format("成功添加 %d 个 %s 到库存，当前库存: %d", quantity, productName, inventory.get(productName)));
    }

    public void queryInventory(String productName) {
        if (inventory.containsKey(productName)) {
            JOptionPane.showMessageDialog(null,
                    String.format("%s 的当前库存为: %d", productName, inventory.get(productName)));
        } else {
            JOptionPane.showMessageDialog(null,
                    String.format("%s 不在库存中。", productName));
        }
    }

    public void updateInventory(String productName, int newQuantity) {
        if (inventory.containsKey(productName)) {
            inventory.put(productName, newQuantity);
            JOptionPane.showMessageDialog(null,
                    String.format("%s 的库存已更新为: %d", productName, inventory.get(productName)));
        } else {
            JOptionPane.showMessageDialog(null,
                    String.format("%s 不在库存中，无法更新。", productName));
        }
    }
}

